home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / spoc88 / cflt20 / tan.c < prev   
Text File  |  1988-04-15  |  610b  |  28 lines

  1. #define NUM_TERMS   15
  2. double approx_tan(double x)
  3. {
  4.      int i;
  5.      long double x2 = x*x, y = 0;
  6.      if (x == 0) return 0;
  7.      for (i = 2*NUM_TERMS-1; i >= 0; i -= 2)
  8.           y = i - x2 / y;
  9.      return x / y;
  10. }
  11.  
  12. /* for _control87 */
  13. #include <float.h>
  14. /* for tan */
  15. #include <math.h>
  16.  
  17. int cdecl main(int argc, char **argv)
  18. {
  19.      double x, y;
  20.      /* mask all exceptions but denormal */
  21.      _control87(MCW_EM-EM_DENORMAL,MCW_EM);
  22.      x = 2.1;
  23.      y = tan(x);
  24.      printf("tan(%g) = %25.20g\n",x,y);
  25.      y = approx_tan(x);
  26.      printf("approx_tan(%g) = %25.20g\n",x,y);
  27. }
  28.